#include "stdafx.h"
#include "DecorativeLight.h"


DecorativeLight::DecorativeLight(void)
	: _R(20)
	, _color(RGB(255, 0, 0))
{
}


DecorativeLight::~DecorativeLight(void)
{
}
BEGIN_MESSAGE_MAP(DecorativeLight, Graphic)
	ON_WM_PAINT()
END_MESSAGE_MAP()


void DecorativeLight::OnPaint()
{
	CPaintDC dc(this); 

	CBrush brush(_color);
	dc.SelectObject(&brush);

	CRect rect;
	GetClientRect(&rect);
	dc.Ellipse(rect);
}


void DecorativeLight::Serialize(CArchive& ar)
{
	Graphic::Serialize(ar);
	_name.Serialize(ar);

	if (ar.IsStoring())
	{	// storing code
		ar << _R << _color;
	}
	else
	{	// loading code
		ar >> _R >> _color;
	}
}


void DecorativeLight::initPos(CPoint& pt1, CPoint& pt2)
{
	CRect wndRect(pt1, pt1 + CSize(_R, _R));
	MoveWindow(wndRect);

	CSize nameSz = getTextSize(_name._text);
	CRect nameRect(wndRect.TopLeft(), wndRect.TopLeft() + nameSz);
	nameRect.OffsetRect(0, wndRect.Height() + 4);

	_name.MoveWindow(nameRect);
}